<template>
	<view class="main">
		<view class="list">
			<view class="item" v-for="(item,i) in list" :key='i'>
				<view class="info">
					<u-avatar size="32" :src="item.to_portrait"></u-avatar>
					<view class="left">
						<view class="title">
							{{item.to_nickname||'用户' }}
						</view>
						<view class="num">
							{{item.create_time}}
						</view>
					</view>
				</view>
				<view class="right">
					<view class="title">
						{{item.type|status}}{{item.money>0?'￥':''}}{{item.money}}
					</view>
				</view>
			</view>
			<block v-if="list.length<1">
				<Empty text="暂无数据" :type='3'></Empty>
			</block>
		</view>

	</view>
</template>

<script>
	import Empty from '@/components/Empty.vue'
	export default {
		components: {
			Empty
		},
		data() {
			return {
				current: 0,
				tabs: [{
					name: "全部"
				}, {
					name: "收入"
				}, {
					name: "支出"
				}],
				page: 1,
				size: 10,
				totalList: [],
				list: [],
				total: 0,
			}
		},
		onLoad(e) {
			this.id = e.id
		},
		onShow() {
			this.getList()
		},
		onPullDownRefresh() {
			this.page = 1
			this.getList()
		},
		onReachBottom() {
			if (this.list.length < this.total) {
				this.getList()
			}
		},
		filters: {
			status(e) {
				switch (e) {
					case 1:
						return '买入'
						break;
					case 8:
						return '挂售'
						break;
					default:
						return ''
						break;
				}
			},
		},
		methods: {
			topage(e) {
				uni.setStorage({
					key: 'sinfo',
					data: e,
					success: () => {
						uni.navigateTo({
							url: '/pages/wallet/info'
						})
					}
				})

			},
			changeTab(e) {
				this.page = 1;
				this.current = e.index;
				this.getList();
			},
			async getList() {
				let data = await this.$http({
					url: this.$api.goodsLog,
					method: 'post',
					hideLoading: true,
					data: {
						page: this.page,
						page_size: this.size,
						id: this.id
					}
				})
				console.log("****" + JSON.stringify(data) + "****" + this.current)
				if (data.code == 200) {
					if (this.page == 1) {
						this.list = []
					}
					let list = data.data
					this.total = list.total
					if (this.list.length < list.total) {
						this.list = this.list.concat(list.data)
						this.page += 1
					}
				} else {
					return []
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		.list {
			padding: 32rpx 32rpx;

			.item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-bottom: 28rpx;
				margin-bottom: 28rpx;
				border-bottom: 1rpx solid #f5f5f5;
				
				.info {
					display: flex;
					align-items: center;
					.left {
						display: flex;
						flex-direction: column;
						justify-content: flex-start;
						margin-left: 10rpx;
					}
				}

				

				.right {
					display: flex;
					flex-direction: column;
					justify-content: flex-end;
					align-items: flex-end;
				}

				.title {
					font-size: 28rpx;
					font-family: PingFangSC-Semibold, PingFang SC;
					font-weight: 600;
					color: #141516;
					line-height: 40rpx;
					margin: 5rpx 0;
				}

				.num {
					margin: 5rpx 0;
					font-size: 22rpx;
					font-family: PingFangSC-Semibold, PingFang SC;
					// font-weight: 600;
					color: #c1c1c1;
					line-height: 32rpx;
				}

			}
		}
	}
</style>
